// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuex from 'vuex'
import store from './store'
import Element from 'element-ui'
import VueQuillEditor from 'vue-quill-editor'
import axios from './api/getData.js'
import 'element-ui/lib/theme-chalk/index.css';
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import '@/assets/css/common.css'
import '@/assets/css/public.css'
import '@/icons'

Vue.use(Vuex)
Vue.use(Element)
Vue.use(VueQuillEditor)
Vue.use(iView);
Vue.config.productionTip = false
Vue.prototype.$Axios = axios

// 公共组件导入
import leftMenu from '@/components/headerMenu/leftMenu.vue'
import tagsPageOpened from '@/components/headerMenu/tagsPageOpened.vue'
import commonTab from './components/commonTab/commonTab.vue'

Vue.component('common-tab', commonTab);
Vue.component('left-menu', leftMenu);
Vue.component('tags-page-opened', tagsPageOpened);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})


router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  if (to.matched.some(r => r.meta.requireAuth)) {
    if (store.state.token) {
      next()
    } else {
      next({
        path: '/',
        query: {redirect: to.fullPath}
      })
    }
  } else {
    next()
  }
})
